#include <iostream>
#include <string>
#include <cctype>
using namespace std;

class Solution
{
public:
    bool isPalindrome(string s) {
        int len = s.size();
        for (int i = 0; i < len; ++i) if(s[i]<='Z' && s[i]>='A') s[i] = s[i]-'A'+'a';
        int i=0, j=len-1;
        while(i<j) {
            while(i<len && !isalnum(s[i])) i++;
            while(j>-1 && !isalnum(s[j])) j--;
            if (i<len && j>-1 && s[i]!=s[j]) return false;
            i++;
            j--;
        }
        return true;
    }
};

int main(int argc, char *argv[])
{
    //string a("A man, a Plan, a canal: panama");
    //string a("race a car");
    //string a(",,,.123.1234121212");
    string a("r.r.");
    Solution ss;
    std::cout << ss.isPalindrome(a)<<std::endl;
    return 0;
}
